// 跨层通信: createContext
import React, { createContext, useContext } from "react";

// 创建一个 Context
const MsgContext = createContext();

function A () {
  return (
    <div>
      A: 
      <B />
    </div>
  )
}

function B () {
  const { msg } = useContext(MsgContext);
  return (
    <div>
     B
     { msg }
    </div>
  )
}

function App () {
  return (
    <div>
      <MsgContext.Provider value={{msg: 'hello'}}>
        App:
        <A />
      </MsgContext.Provider>
    </div>
  )
}
export default App;